package my.avoskagae.store.gaejdo.entity;

import java.io.Serializable;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import my.avoskagae.model.entity.Product;

@PersistenceCapable(detachable="true")
public class ProductImpl implements Product, Serializable {

	private static final long serialVersionUID = 2L;

	@PrimaryKey
	@Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true" )
	private String key;
	
	@Persistent
	private String name;
	
	@Persistent
	private Boolean needPurchase;
	
	@Persistent
	private UserDataStoreImpl userDataStore;
	
	@Override
	public String getName() {
		return name;
	}

	@Override
	public void setName(String name) {
		this.name = name;
	}

	public String getKey() {
		return key;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj.getClass().equals(this.getClass()) &&
				this.getKey().equals(((ProductImpl)obj).getKey())) {
			return true;
		}
		return false;
	}

	public UserDataStoreImpl getUserDataStore() {
		return userDataStore;
	}

	public void setUserDataStore(UserDataStoreImpl userDataStore) {
		this.userDataStore = userDataStore;
	}

	@Override
	public Boolean getNeedPurchase() {
		//TODO эта проверка хранилище или бизнес логика?
		return needPurchase==null?false:needPurchase;
	}

	@Override
	public void setNeedPurchase(Boolean needPurchase) {
		this.needPurchase = needPurchase;
	}

}
